#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "app_runtime.h"


//主窗口过程
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    switch (message){                  
        case WM_DESTROY:
            PostQuitMessage(0);
            break;           
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 1;
}

//注册主窗口类
BOOL RegisterWindowClass(HINSTANCE inst){
    WNDCLASS wc = {0};
    wc.style = CS_VREDRAW|CS_HREDRAW;    
    wc.hIcon = LoadIcon(inst, MAKEINTRESOURCE(1));
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpfnWndProc = MainWndProc;
    wc.hInstance = inst;     
    wc.lpszClassName = TEXT("MainWindowClass");
    return RegisterClass(&wc);
}


int app_main_loop(){
    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0)){
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam; 
}

//入口函数
int WINAPI _tWinMain(HINSTANCE hInst,HINSTANCE hPrev,LPTSTR lpCmdLine,int nCmdShow){
	RegisterWindowClass(hInst);	
	HWND hwnd = CreateWindow(TEXT("MainWindowClass"),TEXT("Demo App"),
        //(WS_OVERLAPPED|WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU), //固定窗口大小
        WS_OVERLAPPEDWINDOW,  //可变窗口大小
        CW_USEDEFAULT,CW_USEDEFAULT,400,300,NULL,NULL,hInst,NULL);		
	ShowWindow(hwnd, nCmdShow);   
    
    app_main(1, NULL);
    return -1;
}
